#!/usr/bin/env node
const https = require('https'),
      log = console.log,
      cheerio = require('cheerio'),
      addr = 'https://maoyan.com/films?showType=3',
      fs = require('fs'),
      url =require('url'),
      http = require('http'),
      qs = require('querystring');
let list = [];

let movieList = require('./data.js');
log(movieList);
movieList = movieList.filter(item=>item.movieRange !== '暂无评分');
function compare(p){
  return function(a,b){
    return a[p]-b[p]
  }
}
movieList.sort(compare('movieRange'))
log('\n');
log(movieList)

function getPage(){
  let html = fs.readFileSync('./index.html').toString('utf8');
  return html;
}

http.createServer((req,res)=>{


  
  if(req.url === '/'){
    res.end(getPage());

  }
  if(req.url === '/getlist'){
    res.end(JSON.stringify(movieList));
  }
 

}).listen(8080);
  





